# -*- coding: utf-8 -*-

import numpy as np
import pandas as pd

"""
risk parity
风险平价


"""


def check_bound(dim, upper_bound: str, lower_bound: str) -> bool:
    """
    校验上下限
    :param dim:
    :param upper_bound:
    :param lower_bound:
    :return:
    """

    upper_bound_list = upper_bound.split('_')
    lower_bound_list = lower_bound.split('_')

    upper_bound_sum = 0
    lower_bound_sum = 0
    # 上下限求和
    for i in range(dim):
        upper_bound_sum += upper_bound_list[i]
        lower_bound_sum += lower_bound_list[i]
        if upper_bound_list[i] < lower_bound_list[i]:
            return False
        pass

    if upper_bound_sum < 1:
        return False
    if lower_bound_sum > 1:
        return False

    pass


def calc(W, SUM):
    # 计算W * SUM
    tmp = np.dot(W, SUM)
    sigma = np.sqrt(np.dot(np.transpose(W), tmp))

    MRC = tmp / sigma
    RC = np.multiply(MRC, W)

    result = RC / sigma
    return sum((result - 1 / len(W)) ** 2)


if __name__ == '__main__':
    # 维度
    dim = 10

    # 上下限
    upper_bound = []
    lower_bound = []

    pass
